<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>microinfinity-cruizcore-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     MICC,                sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: microinfinity-cruizcore-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * microinfinity-cruizcore.h provides an API for the MicroInfinity CruizCore XG1300L sensor.</span>
<span class="comment"> * This program demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to MicroInfinity for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 29 May 2011</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="microinfinity-cruizcore_8h.html" title="MicroInfinity CruizCore XG1300L driver.">drivers/microinfinity-cruizcore.h</a>&quot;</span>

task main () {
  <span class="keywordtype">int</span> _x_accel = 0;
  <span class="keywordtype">int</span> _y_accel = 0;
  <span class="keywordtype">int</span> _z_accel = 0;

  <span class="keywordtype">int</span> angleI = 0;
  <span class="keywordtype">float</span> angleF = 0.0;

  <span class="keywordtype">int</span> rotI = 0;
  <span class="keywordtype">float</span> rotF = 0.0;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;MicroInfinity&quot;</span>);
  nxtDisplayTextLine(1, <span class="stringliteral">&quot;CruizCore XG1300L&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 1&quot;</span>);
  wait1Msec(2000);
  eraseDisplay();

  <span class="comment">// There are 3 ranges the Cruizcore XG1300L can measure in</span>
  <span class="comment">// up to 2G</span>
  <span class="comment">// up to 4G</span>
  <span class="comment">// up to 8G</span>
  <a name="a0"></a><a class="code" href="group__cruizcore.html#gaddcface0963145b35306d010d95ab04c">MICCsetRange8G</a>(MICC);

  <span class="comment">// Make sure you always reset the sensor at the beginning of your program</span>
  <span class="comment">// The robot needs to be completely stationary or your heading and gyro</span>
  <span class="comment">// data won&#39;t be accurate.</span>
  <a name="a1"></a><a class="code" href="group__cruizcore.html#ga7b6b0769eca3edca8d7a82fb152200f8">MICCreset</a>(MICC);

  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();

  nxtDisplayTextLine(0, <span class="stringliteral">&quot;CruizCore XG1300L&quot;</span>);
  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// Read the relative heading from the sensor.</span>
    angleI = <a name="a2"></a><a class="code" href="group__cruizcore.html#ga0b366d3bf46cc3430aaa12e0849074c4">MICCreadRelativeHeading</a>(MICC);
    angleF = angleI / 100.0;

    <span class="comment">// Read the rate of turn</span>
    rotI = <a name="a3"></a><a class="code" href="group__cruizcore.html#ga3fdcaa677edaef65f350e9a9d5ee24a2">MICCreadTurnRate</a>(MICC);
    rotF = rotI / 100.0;

    <span class="comment">// Read the acceleration data from the sensor</span>
    <span class="keywordflow">if</span> (!<a name="a4"></a><a class="code" href="group__cruizcore.html#gaeda9486ec6cfd506b155d84bcd2f7b64">MICCreadAccel</a>(MICC, _x_accel, _y_accel, _z_accel)) {
      nxtDisplayTextLine(4, <span class="stringliteral">&quot;ERROR!!&quot;</span>);
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayTextLine(2, <span class="stringliteral">&quot;Heading: %4.2f&quot;</span>, angleF);
    nxtDisplayTextLine(3, <span class="stringliteral">&quot;RoT:     %4.2f&quot;</span>, rotF);
    nxtDisplayTextLine(5, <span class="stringliteral">&quot;X:      %5.2f&quot;</span>, _x_accel/100.0);
    nxtDisplayTextLine(6, <span class="stringliteral">&quot;Y:      %5.2f&quot;</span>, _y_accel/100.0);
    nxtDisplayTextLine(7, <span class="stringliteral">&quot;Z:      %5.2f&quot;</span>, _z_accel/100.0);
    wait1Msec(50);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: microinfinity-cruizcore-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
